<!-- search -->
<template>
  <div>
    <van-search
    v-model="value"
    show-action
    placeholder="请输入搜索关键词"
    @cancel="$router.back()"
    @search="onSearch"
  />
  <van-cell
      @click="clickFn(index)"
      :title="item"
      v-for="(item,index) in communityList.map(item => item.communityName)"
      :key="index"
    />
  </div>
</template>

<script>
import { cityInfoAPI, xiaoquAPI } from '@/api'
export default {
  data () {
    return {
      value: '',
      title: localStorage.getItem('cityName') || '北京',
      communityList: []
    }
  },
  methods: {
    async onSearch (val) {
      console.log(val)
      const res = await cityInfoAPI({ name: this.title })
      console.log(res)
      const res1 = await xiaoquAPI({
        name: this.title,
        id: res.data.body.value
      })
      console.log(res1)
      this.communityList = res1.data.body
      this.value = val
    },
    clickFn (index) {
      console.log(index)
      this.$store.state.community = this.communityList[index].community
      this.$store.state.communityName = this.communityList[index].communityName
      this.$router.back()
    }
  }
}

</script>
<style lang='less' scoped>
</style>
